1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| public class JdbcDbUtils {
@Test public void fun1() throws SQLException, PropertyVetoException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); dataSource.setMaxPoolSize(20); dataSource.setAcquireIncrement(4); dataSource.setMinPoolSize(5); dataSource.setInitialPoolSize(10);
dataSource.setDriverClass("com.mysql.jdbc.Driver"); dataSource.setJdbcUrl("jdbc:mysql://localhost/java"); dataSource.setUser("root"); dataSource.setPassword("");
QueryRunner qr=new QueryRunner(dataSource); String sql="select * from user where id = ?"; Object[] params={1}; final Object query = qr.query(sql, new BeanHandler<UserBean>(UserBean.class), params); System.out.println(query); }
@Test public void fun2() throws SQLException, PropertyVetoException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); dataSource.setMaxPoolSize(20); dataSource.setAcquireIncrement(4); dataSource.setMinPoolSize(5); dataSource.setInitialPoolSize(10);
dataSource.setDriverClass("com.mysql.jdbc.Driver"); dataSource.setJdbcUrl("jdbc:mysql://localhost/java"); dataSource.setUser("root"); dataSource.setPassword("");
QueryRunner qr=new QueryRunner(dataSource); String sql="select * from user"; final Object query = qr.query(sql, new BeanListHandler<UserBean>(UserBean.class)); System.out.println(query); }
@Test public void fun3() throws SQLException, PropertyVetoException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); dataSource.setMaxPoolSize(20); dataSource.setAcquireIncrement(4); dataSource.setMinPoolSize(5); dataSource.setInitialPoolSize(10);
dataSource.setDriverClass("com.mysql.jdbc.Driver"); dataSource.setJdbcUrl("jdbc:mysql://localhost/java"); dataSource.setUser("root"); dataSource.setPassword("");
QueryRunner qr=new QueryRunner(dataSource); String sql="select * from user where id = ?"; Object[] params={1}; final Object query = qr.query(sql, new MapHandler(), params); System.out.println(query); } @Test public void fun4() throws SQLException, PropertyVetoException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); dataSource.setMaxPoolSize(20); dataSource.setAcquireIncrement(4); dataSource.setMinPoolSize(5); dataSource.setInitialPoolSize(10);
dataSource.setDriverClass("com.mysql.jdbc.Driver"); dataSource.setJdbcUrl("jdbc:mysql://localhost/java"); dataSource.setUser("root"); dataSource.setPassword("");
QueryRunner qr=new QueryRunner(dataSource); String sql="select * from user "; Object[] params={1}; final Object query = qr.query(sql, new MapListHandler()); System.out.println(query); } }
|